@extends('layouts.app')

@section('htmlheader_title')
	基础设置
@endsection

@section('contentheader_title')
	基础设置
@endsection

@section('contentheader_description')
	关键词管理
@endsection

@section('main-content')

	<div class="page-header">
		<button class="btn btn-lg btn-success" onclick="window.location.href='{{url('BaseSet/add')}}'">
			<i class="ace-icon fa fa-pencil align-top bigger-125"></i>
			添加关键词
		</button>
		<button class="btn btn-lg btn-warning"  onclick="setSubscribe()">
			<i class="ace-icon fa fa-pencil align-top bigger-125"></i>
			设置关注回复
		</button>
		<button class="btn btn-lg btn-info"  onclick="setReply()">
			<i class="ace-icon fa fa-pencil align-top bigger-125"></i>
			设置自动回复
		</button>
	</div>
	<div class="box">
		<div class="box-body">
			<table id="example1" class="table table-striped table-bordered ">
				<input type="hidden" id="token" name="_token" value="{{ csrf_token() }}">
				<thead>
				<tr>
					<th width="5%">选择</th>
					<th width="5%">ID</th>
					<th width="12%">关键词</th>
					<th width="8%">类型</th>
					<th width="30%">内容</th>
					<th width="7%">排序</th>
					<th width="12%">添加时间</th>
					<th width="12%">操作</th>
				</tr>
				</thead>

				<tbody>
				@foreach($data as $keyword)
					<tr>
						<td class="center">
							<input name="ckSubscribe" type="checkbox"   value="{{ $keyword->id  }}">
						</td>
						<td class="center">{{ $keyword->id }}</td>
						<td>
							{{ $keyword->keyword }}

							@if ($keyword->is_attention)
								<br/>
								<span class="label label-warning arrowed">关注回复</span>
							@endif

							@if ($keyword->is_auto)
								<br/>
								<span class="label label-info arrowed">自动回复</span>
							@endif

						</td>

						@if ($keyword->type == 1)
							<td><span>图文回复</span></td>
						@elseif ($keyword->type == 2)
							<td><span>图片回复</span></td>
						@else
							<td><span>文本回复</span></td>
						@endif
						<td><span>{{ $keyword->content }}</span></td>
						<td>{{ $keyword->sort }}</td>
						<td>{{ $keyword->created_at }}</td>
						<td>
							<button class="btn btn-xs btn-danger" onclick="del({{ $keyword->id }})">
								<i class="ace-icon fa fa-trash-o bigger-120"></i>
								删除
							</button>
						</td>
					</tr>
				@endforeach
				<tbody>
			</table>
		</div>
	</div>



	<script type="text/javascript">
		// 删除关键词
		function del(id) {
			var url='{{url('BaseSet/del')}}'+'?id='+id;
			location.href=url;
		}


		// 设置关注自动回复
		function setSubscribe(){
			var _token = "{{ csrf_token() }}";
			var arrSubscribe=[];
			$("input:checkbox[name=ckSubscribe]").each(function(){
				if (this.checked ==true) {
					arrSubscribe.push($(this).val());
				}
			});
			if(arrSubscribe.length!=1)
			{
				AlterDialog("提示","请选择一条关键词！");
				$("input:checkbox[name=ckSubscribe]").removeAttr("checked");
				return;
			}

			$.post(
					"/admin/keywordSubscribe",
					{id:arrSubscribe[0], _token:_token},
					function(json){
						if(json.code==0)
						{
							AlterDialog("提示",json.message,function(){
								window.location.reload(true);
							});
						}
						else
						{
							AlterDialog("提示",json.message);
						}
					}
					,"json"
			);}


		// 设置自动回复
		function setReply()
		{
			var _token = "{{ csrf_token() }}";
			var arrReply=[];
			$("input:checkbox[name=ckSubscribe]").each(function(){
				if (this.checked ==true) {
					arrReply.push($(this).val());
				}
			});
			if(arrReply.length!=1)
			{
				AlterDialog("提示","请选择一条关键词！");
				$("input:checkbox[name=ckSubscribe]").removeAttr("checked");
				return;
			}

			$.post(
					"/admin/keywordReply",
					{id:arrReply[0], _token:_token},
					function(json){
						if(json.code==0)
						{
							AlterDialog("提示",json.message,function(){
								window.location.reload(true);
							});
						}
						else
						{
							AlterDialog("提示",json.message);
						}
					}
					,"json"
			);
		}
	</script>


	<div id="AlterDialog" class="hide">
	</div>
	<script type="text/javascript">
		/*
		 title：小标题
		 content：模态框内容，可写html
		 callback：点击确认后的回调方法，可不写或为null
		 */
		function AlterDialog(title, content, callback) {
			BootstrapDialog.show({
				title: title,
				message: content,
				draggable: true,
				closable: false,
				buttons: [
					{
						label: "<i class='ace-icon fa fa-check'></i> 确定",
						cssClass: 'btn-sm btn-success',
						action: function (dialogItself) {
							dialogItself.close();
							if (callback != undefined && callback != null) callback();
						}
					}]
			});
		}

		function ConfirmDialog(title, content, callback) {
			BootstrapDialog.show({
				title: title,
				message: content,
				draggable: true,
				closable: false,
				buttons: [
					{
						label: "<i class='ace-icon fa fa-check'></i> 确定",
						cssClass: 'btn-sm btn-success',
						action: function (dialogItself) {
							dialogItself.close();
							if (callback != undefined && callback != null) callback(true);
						}
					},
					{
						label: "<i class='glyphicon glyphicon-remove'></i> 取消",
						cssClass: 'btn-sm',
						action: function (dialogItself) {
							dialogItself.close();
							if (callback != undefined && callback != null) callback(false);
						}
					}]
			});
		}
	</script>

@endsection
